home *** CD-ROM | disk | FTP | other *** search
/ Aminet 39 / Aminet 39 (2000)(Schatztruhe)[!][Oct 2000].iso / Aminet / dev / basic / ImageDTInfo.lha / ImageDTInfo / AuxRoutines / GetArg.bas < prev    next >
Encoding:
BASIC Source File  |  2000-08-18  |  4.3 KB  |  136 lines

  1. '   ----------------------------------------------------------------------
  2. '                   Processing the CLI argument(s) string
  3. '              (the program will return the #p% arg asked and
  4. '                will be remove the leading/trailing spaces
  5. '                like the final space inserted by KingCON...
  6. '                   and the initial/final quotation marks).
  7. '     New feature requested by Mr Goertz for the ImageDTInfo project :)
  8. '
  9. '                               ------------
  10. '                Procesando la cadena de argumento(s) CLI
  11. '           (el programa devolverá el argumento nº "p%" pedido
  12. '               y eliminará los espacios iniciales y finales
  13. '                como el insertado al final por KingCON...
  14. '                    y las comillas iniciales/finales).
  15. '                     Nueva prestación pedida por el
  16. '                 Sr. Goertz para el proyecto ImageDTInfo :).
  17. ' ------------------------------------------------------------------------
  18. ' Arguments/Argumentos
  19. '
  20. ' cad$ = Cadena de argumentos CLI/Shell
  21. '        (habitualmente obtenida con COMMAND$)
  22. '
  23. '        CLI/Shell arguments string
  24. '        (habitually the string returned by COMMAND$)
  25. '
  26. ' p%   = Nº (posición) del argumento pedido. Número entero >=1.
  27. '
  28. '        The argument asked (position).  Integer number >=1.
  29.  
  30. ' Returned/Devuelve...
  31. '
  32. '        O una cadena nula (no existe el argumento
  33. '        nº "p%" pedido) O el argumento solicitado.
  34. '
  35. '        Or a null string (don't exists
  36. '        the argument #"p%") OR the argument requested
  37. '
  38. ' -----------------------------------------------------------------------
  39.  
  40. FUNCTION getarg$(cad$,p%)
  41. LOCAL num%,quotes%,char%,cadtmp$,a%
  42.  
  43.     getarg$=""
  44.  
  45.     ' ---------------- Anti bad coders };D. Remember! p% must be >=1 !! ------------
  46.     ' - Protección contra malos programadores };D. Recuerde ¡¡ p% ha de ser >=1 !! -
  47.     ' ------------------------------------------------------------------------------
  48.     IF p% <=0 THEN p%=1
  49.  
  50.     WHILE cad$ <> ""
  51.  
  52.         ' --------- Removing not necesary spaces (start/end) -----------
  53.         ' - Suprimir espacios innecesarios (inicio/final de la cadena) -
  54.         ' --------------------------------------------------------------
  55.         cad$=LTRIM$(RTRIM$(cad$))
  56.  
  57.         num%    = 1
  58.         cadtmp$ = ""
  59.         quotes% = 0
  60.  
  61.         FOR a%=1 TO LEN(cad$)
  62.  
  63.             char%=ASC(MID$(cad$,a%,1))
  64.  
  65.                 SELECT CASE char%
  66.  
  67.                     ' ------ Modifying quotes status -------
  68.                     ' - Modificando estado de las comillas -
  69.                     ' --------------------------------------
  70.                     CASE 34
  71.                     quotes% = NOT quotes%
  72.  
  73.                     ' -- Spaces/ Espacios --
  74.                     ' ----------------------
  75.                     CASE 32
  76.                     IF quotes% = 0 THEN
  77.                         ' --- The space is an arguments separator ---
  78.                         ' - El espacio es un separador de argumentos-
  79.                         ' -------------------------------------------
  80.                         IF num%=p% THEN
  81.                             ' --------- Parse arg asked... end ---------
  82.                             ' - Procesado argumento pedido... terminar -
  83.                             ' ------------------------------------------
  84.                             EXIT FOR
  85.                         ELSE
  86.                             '-- Parse the next character (and argument) --
  87.                             '- Procesar siguiente carácter (y argumento) -
  88.                             ' --------------------------------------------
  89.                             num%=num%+1%
  90.                             EXIT SELECT
  91.                         END IF
  92.                     ELSE
  93.                         ' --------- To preserve space for the argument asked (quoted) ---------
  94.                         ' -- Preservar espacios del argumento pedido si están entre comillas --
  95.                         ' ---------------------------------------------------------------------
  96.                         IF num%=p% THEN cadtmp$=cadtmp$+CHR$(char%)
  97.                     END IF
  98.  
  99.                     ' --- Preserve others characters (only for the argument asked) ----
  100.                     ' - Preservar el resto de los caracteres para el argumento pedido -
  101.                     ' -----------------------------------------------------------------
  102.                     CASE ELSE
  103.                     IF num%=p% THEN cadtmp$=cadtmp$+CHR$(char%)
  104.  
  105.                 END SELECT
  106.  
  107.         NEXT a%
  108.  
  109.         cad$ = cadtmp$
  110.  
  111.         ' --------------- Template info ---------------
  112.         ' - Información sobre la sintaxis del comando -
  113.         ' ---------------------------------------------
  114.  
  115.         IF cad$ = "?" THEN
  116.  
  117.             PRINT CadLc$(MSG_TEMPLATE&);"/A: ";
  118.             INPUT "",cad$
  119.  
  120.         ELSE
  121.  
  122.             ' ---------- Exit point if cad$<>"" -----------
  123.             ' - Punto de salida de la función si cad$<>"" -
  124.             ' ---------------------------------------------
  125.             getarg$=cad$
  126.             EXIT WHILE
  127.  
  128.         END IF
  129.  
  130.     WEND
  131.  
  132. ' ---------- Exit point if cad$="" -----------
  133. ' - Punto de salida de la función si cad$="" -
  134. ' --------------------------------------------
  135. END FUNCTION
  136.